Skip to main content

Create an Entity

Overview

This document describes how to create an entity in any work system using the SyncNow DevOps Gate. You can use Groovy scripts for Jenkins or copy cURL commands directly from the DevOps Gate project configuration in the SyncNow UI.

Overview


πŸ’‘ Usage Examples

  • Create a bug when automated testing fails.
  • Create a bug when a security vulnerability is found.
  • Create a service ticket when an incident is identified in another system.

✨ Creating an Entity

This procedure creates an entity according to the mapping definition. If an entity with the same title/summary or matching a defined filter exists, SyncNow will update it instead of creating a duplicate.

Create An Entity


πŸ“¨ API Request

The request URL should include the system ID, which can be copied from the DevOps Process definition page.

POST /api/v1.0/DevOpsGate/Enrich/{DevOpsProjectID}?action=create

Request Body Parameters:

ParameterDescription
Param1…ParamXParameters as defined in the DevOps Gate per entityType mapping
subProjectThe target work system project as defined in the DevOps Gate Process. Work systems for publishing can be limited through SyncNow DevOps Process configuration
entityTypeThe entity to be created
CreateIfEntityDoesNotExistByTitleOtherwiseUpdateWhether to create an entity if found a similar one with the same title

Sample Payload:

[
  {
    "fields": [
      { "key": "Param1", "value": "string" },
      { "key": "Param2", "value": "string" },
      { "key": "Param3", "value": "string" }
    ],
    "subProject": "MyProject",
    "entityType": "Bug",
    "CreateIfEntityDoesNotExistByTitleOtherwiseUpdate": "false"
  }
]

🟒 API Response

FieldDescription
systemIDThe system where the entities were created
entityKeysThe IDs of the entities created
errorsErrors that occurred during creation
warningsWarnings that occurred during creation

Sample Response:

{
  "updatedEntitiesID": [
    {
      "systemID": "10",
      "entityKeys": ["CLS-3938"]
    }
  ],
  "errors": [],
  "warnings": []
}

πŸ€– Jenkins Groovy Script Example

Below is a Groovy code example for Jenkins that creates an entity with SyncNow DevOps Gate:

@NonCPS
def getCommentsString() {
    def list = []
    def changeLogSets = currentBuild.changeSets
    for (int i = 0; i < changeLogSets.size(); i++) {
        def entries = changeLogSets[i].items
        for (int j = 0; j < entries.length; j++) {
            def entry = entries[j]
            if (entry.msg != null) {
               list.add("""${entry.commitId} on ${new Date(entry.timestamp)}: ${entry.msg.replaceAll("[\n\r]", " ")}""")
            }
        }
    }
    return list.join(',')
}

pipeline {
    agent any
    stages {
        stage('Clone') { steps { echo 'Clone Code' } }
        stage('Version') { steps { echo 'Version' } }
        stage('Test') { steps { echo 'Test' } }
        stage('Build') { steps { echo 'Build' } }
        stage('Publish') { steps { echo 'Publish' } }
        stage('Notify SyncNow') {
            steps {
                echo 'Notify'
                echo "Job Name is ${JOB_NAME}, Build ID is ${env.BUILD_ID}"
                script {
                    def commits = getCommentsString()
                    def payload = """
[{
  "fields": [
    { "key": "Param1", "value": "string" },
    { "key": "Param2", "value": "string" },
    { "key": "Param3", "value": "string" }
  ],
  "subProject": "MyProject",
  "entityType": "Bug"
}]
                    """
                    def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', authentication: 'SyncNow', requestBody: "${payload}", url: "https://<SyncNowBaseURL>/api/v1.0/DevOpsGate/Enrich/<DevOpsProjectID>?action=create"
                    println("Status: ${response.status}")
                    println("Content: ${response.content}")
                }
            }
        }
    }
}

πŸ“ Step-by-Step Instructions

Example: Create or Update an Entity

  1. Create a DevOps Gate Process.

  2. Navigate to the Mapping Entities page.

  3. Go to the Mapping Options page for specific entity mappings.

    Navigate To Mapping Page

  4. Add filters (e.g., filter by Status).

    Duplicate Detection: Entity names are always checked by their summary/title. If an entity with the same name/title and type is found, it will be updated.

    Filter Entities For Update

  5. Go to the DevOps Gate Process Configuration and press the How It Works link.

    DevOps Gate Configuration

  6. Select "Create & Update Entities from Commits".

    How It Works

  7. Copy the cURL command.

    Copy cURL

  8. Paste it into a command line. Set the correct sub-project and execute.

    Paste Into Command Line

  9. Change the content of the fields as needed and execute again.
    A new entity will be created with information from both DevOps Gate calls.

    New Entity Created

  10. Change the status of the entity.

    Change Status

  11. Execute the cURL command again.
    A new entity will be created.

    cURL Execution

    Test Create Action


Tip:
Use filters and duplicate detection to avoid creating unnecessary duplicates and to keep your work systems clean and up to date.